#include "graph.h"
/* Good luck */
void depth_first(Graph * theGraph, int visited[], int start, int nodeNum, Value*high)
{
  //printf("%d\n", high -> bestCount);
  visited[start] = 1;
  List *current;
  current = (List*)malloc(sizeof(List));
  current = theGraph->table[start].outlist;
  //printf("%d\n", current -> index); 
  while(current != NULL)
  {
    //printf("asdasd  = >> %d\n", current -> index);
    if((visited[current -> index]) == 0)
    {
      high -> bestCount++;
      
      //printf("i am here.%d\n", high -> bestCount);
      if(nodeNum <  theGraph -> table[start].outdegree)
      {
        high -> bestNode = start;
        //printf("%d\n", value[0]);
	nodeNum = theGraph -> table[start].outdegree;
      }
      depth_first(theGraph, visited, current -> index, nodeNum, high);
    }
    else
    {
      //printf("I am in next");
      current = current -> next;
      //printf("next Value %d\n", current->index);
    }
  }     
}


void breadth_first(Graph * theGraph, int start, Value * high)
{   
  int visited[theGraph -> MaxSize + 1];
  int theQueue[theGraph -> MaxSize + 1];
  for(int ini = 0; ini < theGraph -> MaxSize + 1; ini++)
  {
    visited[ini] = 0;
    theQueue[ini] = 0;
  }
  //visited[start] = 1;
  //theQueue[0] = start;
  visited[start] = 1;
  int i = 0;
  int j = -1;
  int bestNum = 0;
  int boolean = 1;
  List *current;
  current = (List*)malloc(sizeof(List));
  current = theGraph->table[start].outlist;  
  //printf ("MAX %d\n", current -> index);
  
  while(boolean == 1)
  { 
    //printf("the Number is %d\n", start);       
    if(current == NULL)
    {
      if(theQueue[i] == 0 || i > theGraph -> MaxSize)
      {
        break;
      }//if
      else
      {
        current = theGraph->table[theQueue[i]].outlist;
        //printf("%d\n", theQueue[i]);
        i++;
      }//else
    }//if
    else
    {
      while(current != NULL)
      { 
        
        if(visited[current -> index] == 0)
        {
          //printf("I am here!%d\n", current -> index);
          high -> bestCount ++;
	  visited[current -> index] = 1;
          theQueue[++j] = current -> index;

          if(bestNum < theGraph->table[current -> index].outdegree)
          {
            bestNum = theGraph->table[current -> index].outdegree;
            high -> bestNode = current -> index;
          }//first if          
        }//if
        current = current -> next;
      }//while
      //current = current -> next;
    }//else    
  }//while
}//breadth_first

